/**
 * 
 */
package it.fuesi.signit;

import android.app.Activity;
import android.content.SharedPreferences;
import android.net.Uri;

/**
 * @author pascotto
 *
 */
public class CurrentSettings {

	private static final String PREF_SIGNATURE = "SIGNATURE";
	private static final String PREF_SIGNATURE_SIZE = "SIGNATURE_SIZE";
	private static final String PREF_SIGNATURE_POSITION = "SIGNATURE_POSITION";
	private static final String PREF_SIGNATURE_MARGINS = "SIGNATURE_MARGINS";
	private static final String PREF_SIGNATURE_STROKE = "SIGNATURE_STROKE";
	private static final String PREF_SIGNATURE_COLOR_R = "SIGNATURE_COLOR_R";
	private static final String PREF_SIGNATURE_COLOR_G = "SIGNATURE_COLOR_G";
	private static final String PREF_SIGNATURE_COLOR_B = "SIGNATURE_COLOR_B";
	private static final String PREF_SIGNATURE_TYPE_FACE = "SIGNATURE_TYPE_FACE";
	private static final String PREF_SIGNATURE_TYPE_FACE_STYLE = "SIGNATURE_TYPE_FACE_STYLE";
	private static final String PREF_CURRENT_IMAGE = "CURRENT_IMAGE";
	private static final String PREF_IMAGE_SIGNED = "IMAGE_SIGNED";
	
	public static final int POSITION_BOTTOM_LEFT = 0;
	public static final int POSITION_BOTTOM_CENTER = 1;
	public static final int POSITION_BOTTOM_RIGHT = 2;
	public static final int POSITION_TOP_LEFT = 3;
	public static final int POSITION_TOP_CENTER = 4;
	public static final int POSITION_TOP_RIGHT = 5;
	
	
	
	private static CurrentSettings instance = null;
	
	private String signature;
	private int size;
	private int position;
	private int margin;
	private int stroke;
	private int colorR;
	private int colorG;
	private int colorB;
	private int typeFace;
	private int typeFaceStyle;
	private Uri currentImageUri;
	private boolean imageSigned = false;

	private SharedPreferences mPrefs;
	
	public static CurrentSettings instance(Activity context){
		if(instance == null)
			instance = new CurrentSettings(context);
		
		return instance;
	}
	
	private CurrentSettings(Activity context){
		super();
		mPrefs = context.getPreferences(Activity.MODE_PRIVATE);
		load();
	}
	
	private void load(){
		signature = mPrefs.getString(PREF_SIGNATURE, null);
		size = mPrefs.getInt(PREF_SIGNATURE_SIZE, R.id.sizeSmall);
		position = mPrefs.getInt(PREF_SIGNATURE_POSITION, 0);
		margin = mPrefs.getInt(PREF_SIGNATURE_MARGINS, 5);
		stroke = mPrefs.getInt(PREF_SIGNATURE_STROKE, 5);
		colorR = mPrefs.getInt(PREF_SIGNATURE_COLOR_R, 0);
		colorG = mPrefs.getInt(PREF_SIGNATURE_COLOR_R, 0);
		colorB = mPrefs.getInt(PREF_SIGNATURE_COLOR_R, 0);
		typeFace = mPrefs.getInt(PREF_SIGNATURE_TYPE_FACE, 0);
		typeFaceStyle = mPrefs.getInt(PREF_SIGNATURE_TYPE_FACE_STYLE, 0);
		final String currentImage = mPrefs.getString(PREF_CURRENT_IMAGE, null);
		if(currentImage != null)
			currentImageUri = Uri.parse(currentImage);
		imageSigned = mPrefs.getBoolean(PREF_IMAGE_SIGNED, false);
	}
	
	public void save(){
		mPrefs.edit().putString(PREF_SIGNATURE, signature).commit();
		mPrefs.edit().putInt(PREF_SIGNATURE_SIZE, size).commit();
		mPrefs.edit().putInt(PREF_SIGNATURE_POSITION, position).commit();
		mPrefs.edit().putInt(PREF_SIGNATURE_MARGINS, margin).commit();
		mPrefs.edit().putInt(PREF_SIGNATURE_STROKE, stroke).commit();
		mPrefs.edit().putInt(PREF_SIGNATURE_COLOR_R, colorR).commit();
		mPrefs.edit().putInt(PREF_SIGNATURE_COLOR_G, colorG).commit();
		mPrefs.edit().putInt(PREF_SIGNATURE_COLOR_B, colorB).commit();
		mPrefs.edit().putInt(PREF_SIGNATURE_TYPE_FACE, typeFace).commit();
		mPrefs.edit().putInt(PREF_SIGNATURE_TYPE_FACE_STYLE, typeFaceStyle).commit();
		if(currentImageUri != null)
			mPrefs.edit().putString(PREF_CURRENT_IMAGE, currentImageUri.toString()).commit();
		
		mPrefs.edit().putBoolean(PREF_IMAGE_SIGNED, imageSigned).commit();
	}
	
	
	public String getSignature() {
		return signature;
	}
	public void setSignature(String signature) {
		this.signature = signature;
	}
	public int getSize() {
		return size;
	}
	public void setSize(int size) {
		this.size = size;
	}
	public int getPosition() {
		return position;
	}
	public void setPosition(int position) {
		this.position = position;
	}

	public Uri getCurrentImageUri() {
		return currentImageUri;
	}

	public void setCurrentImageUri(Uri currentImageUri) {
		this.currentImageUri = currentImageUri;
	}

	public boolean isImageSigned() {
		return imageSigned;
	}

	public void setImageSigned(boolean imageSigned) {
		this.imageSigned = imageSigned;
	}

	public int getMargin() {
		return margin;
	}

	public void setMargin(int margin) {
		this.margin = margin;
	}

	public int getStroke() {
		return stroke;
	}

	public void setStroke(int stroke) {
		this.stroke = stroke;
	}

	public int getColorR() {
		return colorR;
	}

	public void setColorR(int colorR) {
		this.colorR = colorR;
	}

	public int getColorG() {
		return colorG;
	}

	public void setColorG(int colorG) {
		this.colorG = colorG;
	}

	public int getColorB() {
		return colorB;
	}

	public void setColorB(int colorB) {
		this.colorB = colorB;
	}

	public int getTypeFace() {
		return typeFace;
	}

	public void setTypeFace(int typeFace) {
		this.typeFace = typeFace;
	}

	public int getTypeFaceStyle() {
		return typeFaceStyle;
	}

	public void setTypeFaceStyle(int typeFaceStyle) {
		this.typeFaceStyle = typeFaceStyle;
	}
	
	
	
	
}
